package com.fast.alden.common.util;

import java.util.Date;

public class DateUtils {
    /**
     * 计算时间差
     *
     * @return 数组：[天数，小时数，分钟数，秒数]
     */
    public static long[] timeDiff(Date endDate, Date startTime) {
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - startTime.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        long sec = diff % nd % nh % nm / ns;
        return new long[]{day, hour, min, sec};
    }
}
